<template>
  <div class="app-container">
    <!-- 表格 -->
    <el-table
      :data="articleTypeList"
      border
      fit
      :header-cell-style="{background:'#0078AD',color:'#FFFFFF'}"
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <!-- slot-scope="scope" 属性本质就是一个插槽 -->
        <template slot-scope="scope">
          {{scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="title" label="名称" />
      <el-table-column prop="sort" label="排序" />
      
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/article/editArticleType/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>


  </div>
</template>

<script>
import article from '@/api/edu/article'
export default {
    data() {
        return {
          articleTypeList:null,
        }
    },
    created() {
        this.getArticleTypeList()
    },
    methods: {
        getArticleTypeList() {
            article.getArticleTypeList().then(response => {
                this.articleTypeList = response.data.blogTypeList
            })
        },
        
        //删除类别
        removeDataById(id) {
            this.$confirm('此操作将永久删除该类别, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            //发起请求
            article.deleteArticleTypeById(id)
                .then(response => {
                    this.getArticleTypeList()
                    this.$message({
                    type: 'success',
                    message: '删除成功!'
                  });
                })
          }).catch((response) => { // 失败
            if (response === 'cancel') {
              this.$message({
                type: 'info',
                message: '已取消删除'
              })
            }
          });
        },

    },
}

</script>
